package com.pkx.guide.system.controller;

import com.pkx.guide.common.annotation.ORpose;
import com.pkx.guide.common.constant.SecurityConstants;
import com.pkx.guide.common.result.Result;
import com.pkx.guide.system.model.dto.CaptchaResult;
import com.pkx.guide.system.model.dto.LoginResult;
import com.pkx.guide.system.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Tag(name = "认证中心")
@RestController
@RequestMapping("/auth")
@Slf4j
@ORpose
public class AuthController {

    @Resource
    private AuthService authService;

    @Operation(summary = "登录")
    @PostMapping("/login")
    public LoginResult login(
            @Parameter(description ="用户名") @RequestParam String username,
            @Parameter(description ="密码") @RequestParam String password) {
        return authService.login(username, password);
    }

    @Operation(summary = "注销", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
    @DeleteMapping("/logout")
    public void logout() {
        authService.logout();
    }

    @Operation(summary = "获取验证码")
    @GetMapping("/captcha")
    public CaptchaResult getCaptcha() {
        return authService.getCaptcha();
    }

}
